import React, { Component } from 'react'

export default class App extends Component {
	constructor() {
		super()
		this.state = {
			count: 0
		}
		// 重新创建实例方法 改变函数的方法生成新方法赋值给创建的方法
		this.handelClick = this.handelClick.bind(this)
	}

	handelClick(e) {
		this.setState((state, props) => {
			return {
				count: state.count + 1
			}
		})
	}
	render() {
		return (
			<div style={{ textAlign: 'center' }}>
				<h2>计数器:{this.state.count}</h2>
				<button onClick={this.handelClick}>+1</button>
			</div>
		)
	}
}
